package net.yters.model.agents;
import java.io.IOException;
import java.io.Serializable;
import java.util.Map;
import java.util.TreeMap;
import java.util.Map.Entry;

import net.yters.util.Box;
import net.yters.util.Util;


public abstract class Agent implements Serializable {
	private static final long serialVersionUID = 799600183256753524L;

	public TreeMap<String, Box> f_state = new TreeMap<String, Box>();
	
	static int nextAvailableID = 0;
	public int ID = nextAvailableID;
	public String f_name = this.getClass().getName() + "@" + "agent_id_" + ID;
	public enum Type {SYMBOLIC, NUMERIC};
	

	public Agent() {
		nextAvailableID++;
	}
	
	public Agent(Agent agent) throws IOException, ClassNotFoundException {
		Agent clone = (Agent) Util.deepClone(agent);
		f_state = clone.f_state;
	}
	
	abstract public void execute();

	public String qualifyField(String field) {
		return  f_name + ":" + field;
	}

	// TODO currently unused, need to incorporate a typing system into data export
//	private String setType(String name, Type type) {
//		return "(" + type.name() + ")" + name;
//	}
	
	public void addBoxedState(String name, Box value) {
		f_state.put(qualifyField(name), value);
	}
	
	public void addAllBoxedStates(Map<String, Box> states) {
		for(Entry<String, Box> state : states.entrySet()) {
			addBoxedState(state.getKey(), state.getValue());
		}
	}
	
	public Box getBoxedState(String name) {
		return f_state.get(qualifyField(name));
	}
}
